<template>
  <div>
    <el-form>
      <!--内容-->
      <el-form-item label="">
        <div class="edit_container">
          <Uediter
            :text="text"
            :config="ueditor.config"
            ref="ue"
            @contentChange="contentChangeFunc"
          ></Uediter>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { setCompany } from "@/api/company";
import Uediter from "@/components/UE.vue";
import { ElMessage } from "element-plus";
import { ref, watch } from "vue";
const ue = ref<any>(null);
const props = defineProps({
  content: {
    type: String,
    default: () => {
      return "";
    },
  },
});
const text = ref("");
watch(
  () => props.content,
  (newVal: string) => {
    console.log(newVal);
    if (ue.value) {
      ue.value.setContent(newVal);
    }
  }
);
/*富文本框配置*/
const ueditor = ref({
  text: "",
  config: {
    initialFrameWidth: 1200,
    initialFrameHeight: 600,
  },
});
const contentChangeFunc = (e) => {
  text.value = e;
};

const submit = () => {
  setCompany({
    field: "manager",
    value: text.value,
  }).then((res: any) => {
    if (res.code == 1) {
      ElMessage.success("保存成功");
    } else {
      ElMessage.error(res.msg);
    }
  });
};
</script>

<style lang="scss" scoped></style>
